<template>
  <div class="parent">
    <echartsDom v-if="isShowEcharts" :width="width" :height="height" :option="option" />
    <div v-else>
      <px-empty :image-size="50" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, ref, watch } from "vue";
import echartsDom from "./echartsDom.vue";
import { queryConsumeChartForDay } from "@/api/waterKanban";
const props = defineProps({
  width: {
    type: String,
    default: ""
  },
  height: {
    type: String,
    default: ""
  },
  color: {
    type: String,
    default: "#3B82F6"
  },
  chartvlue: {
    type: Object,
    default: () => {},
    required: true
  }
});
const isShowEcharts = ref(false);
const state = reactive({
  option: {}
});
const { option } = toRefs(state);
const getoptions = () => {
  console.log(props.chartvlue.details.map(item => item.xaxis));
  isShowEcharts.value = true;
  option.value = {
    toolbox: {
      show: true,
      feature: {
        saveAsImage: {
          title: "点击保存为图片"
        }
      }
    },
    color: ["#3B82F6 ", "#39C670"],
    grid: {
      left: "20px",
      top: "40px",
      right: "10px",
      bottom: "10px",
      containLabel: true
    },
    legend: {
      x: "center"
    },
    tooltip: {
      trigger: "axis"
    },
    xAxis: {
      type: "category",
      boundarGap: false,
      // data: response.xaxis
      data: props.chartvlue.details.map(item => item.xaxis)
    },
    yAxis: {
      name: props.chartvlue.unit,
      type: "value"
    },
    series: [
      {
        name: props.chartvlue.itemName,
        // data: response.panelList.filter(item => item.title == "UPW")[0].details.map(item => (item.value != null ? item.value : 0))
        //   ? response.panelList.filter(item => item.title == "UPW")[0].details.map(item => (item.value != null ? item.value : 0))
        //   : [0, 0, 0, 0, 0, 0, 0],
        data: props.chartvlue.details.map(item => item.value),
        type: "line"
      }
    ]
  };
};
watch(
  () => props.chartvlue,
  newOption => {
    console.log(props.chartvlue);
    getoptions();
  },
  { immediate: true }
);
</script>

<style scoped lang="scss">
.parent {
  float: left;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>
